package com.leetcode.math;

import java.util.Arrays;

public class PlusOne {
    public int[] plusOne(int[] digits) {
        int len = digits.length;
        int[] res = new int[len + 1];
        int high = 1;
        for (int i = len - 1; i >= 0; i--) {
            res[i + 1] = (digits[i] + high) % 10;
            high = (digits[i] + high) / 10;
        }
        if (high != 0) {
            res[0] = 1;
            return res;
        } else {
            int[] tmpArr = new int[len];
            for (int i = 0; i < len; i++) {
                tmpArr[i] = res[i + 1];
            }
            return tmpArr;
        }
    }
}
